package cn.edu.scau.cmi.wangmaoren.comprehension.client;

import af.javafx.layout.AfLinearLayout;
import cn.edu.scau.cmi.wangmaoren.client.classicsDesignPattern.AbstractFactoryClient;
import cn.edu.scau.cmi.wangmaoren.client.classicsDesignPattern.AdapterClient;
import cn.edu.scau.cmi.wangmaoren.client.classicsDesignPattern.ConsistentCompositeClient;
import cn.edu.scau.cmi.wangmaoren.client.classicsDesignPattern.FactoryClient;
import cn.edu.scau.cmi.wangmaoren.client.classicsDesignPattern.InterProgrammingClient;
import cn.edu.scau.cmi.wangmaoren.client.classicsDesignPattern.SafeCompositeClient;
import cn.edu.scau.cmi.wangmaoren.client.classicsDesignPattern.SimpleFactoryMethodClient;
import cn.edu.scau.cmi.wangmaoren.client.classicsDesignPattern.SingletonClient;
import javafx.application.Application;
import javafx.geometry.Orientation;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.text.Font;
import javafx.stage.Stage;

public class ComprehensionJavafx extends Application
{
	private AfLinearLayout root = new AfLinearLayout();
	private Button singletonAndMultitionButton = new Button("实验一：单例/多例模式");
	private Button interProgrammingButton = new Button("实验二：接口编程");
	private Button simpleFactoryButton = new Button("实验三：简单工厂");
	private Button factoryButton = new Button("实验三：工厂模式");
	private Button abstractFactoryButton = new Button("实验三：抽象工厂");
	private Button adapterButton = new Button("实验四： 对象/类适配器");
	private Button safeCompositeButton = new Button("实验五：安全型组合模式");
	private Button consistentCompositeButton = new Button("实验五：一致型组合模式");
	private Button springAndHibernateButton = new Button("实验六：Spring集成Hibernate框架");
	private Label label = new Label("           201727010621 王茂任");

	private Label blankTop = new Label();
	private Label blankBottom = new Label();

	@Override
	public void start(Stage primaryStage)
	{
		try
		{
			initLayout();// 初始化界面

			Scene scene = new Scene(root, 400, 750);
			primaryStage.setTitle("综合性实验");
			primaryStage.setScene(scene);
			primaryStage.show();

		} catch (Exception e)
		{
			e.printStackTrace();
		}
	}

	public static void main(String[] args)
	{
		launch(args);
	}

	private void singletonAndMultitionWindow()
	{
		SingletonClient singletonClient = new SingletonClient();
		singletonClient.openWindow();
	}

	private void interProgrammingWindow()
	{
		InterProgrammingClient interProgrammingClient = new InterProgrammingClient();
		interProgrammingClient.openWindow();

	}

	private void simpleFactoryWindow()
	{
		SimpleFactoryMethodClient simpleFactoryMethodClient = new SimpleFactoryMethodClient();
		simpleFactoryMethodClient.openWindow();

	}

	private void factoryWindow()
	{
		FactoryClient factoryClient = new FactoryClient();
		factoryClient.openWindow();

	}

	private void abstractFactoryWindow()
	{
		AbstractFactoryClient abstractFactoryClient = new AbstractFactoryClient();
		abstractFactoryClient.openWindow();

	}

	private void adapterWindow()
	{
		AdapterClient adapterClient = new AdapterClient();
		adapterClient.openWindow();

	}

	private void safeCompositeWindow()
	{
		SafeCompositeClient safeCompositeClient = new SafeCompositeClient();
		safeCompositeClient.openWindow();

	}

	private void consistentCompositeWindow()
	{
		ConsistentCompositeClient consistentCompositeClient = new ConsistentCompositeClient();
		consistentCompositeClient.openWindow();

	}

	private void springAndHibernateWindow()
	{
		ComprehensionHibernateSpringClient comprehensionHibernateSpringClient = new ComprehensionHibernateSpringClient();
		comprehensionHibernateSpringClient.openWindow();
	}

	/*
	 * 初始化界面
	 */
	private void initLayout()
	{
		root.orientation(Orientation.VERTICAL).spacing(20).padding(24);
		root.getChildren().addAll(blankTop, singletonAndMultitionButton, interProgrammingButton, simpleFactoryButton,
				factoryButton, abstractFactoryButton, adapterButton, safeCompositeButton, consistentCompositeButton,
				springAndHibernateButton, label, blankBottom);
		root.layout("1 50px 50px 50px 50px 50px 50px 50px 50px 50px 50px 1");

		singletonAndMultitionButton.setFont(Font.font("华文中宋", 20));
		interProgrammingButton.setFont(Font.font("华文中宋", 20));
		simpleFactoryButton.setFont(Font.font("华文中宋", 20));
		factoryButton.setFont(Font.font("华文中宋", 20));
		abstractFactoryButton.setFont(Font.font("华文中宋", 20));
		adapterButton.setFont(Font.font("华文中宋", 20));
		safeCompositeButton.setFont(Font.font("华文中宋", 20));
		consistentCompositeButton.setFont(Font.font("华文中宋", 20));
		springAndHibernateButton.setFont(Font.font("华文中宋", 20));
		label.setFont(Font.font("华文中宋", 20));

		singletonAndMultitionButton.setOnAction((e) -> {
			singletonAndMultitionWindow();
		});
		interProgrammingButton.setOnAction((e) -> {
			interProgrammingWindow();
		});
		simpleFactoryButton.setOnAction((e) -> {
			simpleFactoryWindow();
		});
		factoryButton.setOnAction((e) -> {
			factoryWindow();
		});
		abstractFactoryButton.setOnAction((e) -> {
			abstractFactoryWindow();
		});
		adapterButton.setOnAction((e) -> {
			adapterWindow();
		});
		safeCompositeButton.setOnAction((e) -> {
			safeCompositeWindow();
		});
		consistentCompositeButton.setOnAction((e) -> {
			consistentCompositeWindow();
		});
		springAndHibernateButton.setOnAction((e) -> {
			springAndHibernateWindow();
		});

	}
}
